Example #1
0
/* -----------------------------------------------------------------------------------------------------------*/
unsigned int UDP_RegisterSocket( unsigned long IP, unsigned int DestinationPort, unsigned int Bufferlenght, unsigned char * UDP_Recivebuffer)
{
	unsigned int SOCKET;
	
	SOCKET = UDP_Getfreesocket();
	
	if ( SOCKET == 0xffff ) return( 0xffff );
	
	UDP_sockettable[SOCKET].Socketstate = SOCKET_READY;
	UDP_sockettable[SOCKET].DestinationPort = ChangeEndian16bit( DestinationPort );
	// wenn Zielport Bootps(67) dann Sourceport auf Bootpc(68) setzen um kommunikation mit DHCP-Server zu ermöglichen
	if ( DestinationPort == 67 )
		UDP_sockettable[SOCKET].SourcePort = ChangeEndian16bit( 68 );
	else
		UDP_sockettable[SOCKET].SourcePort =~ DestinationPort;
		
	UDP_sockettable[SOCKET].DestinationIP = IP;
	UDP_sockettable[SOCKET].Bufferfill = 0;
	UDP_sockettable[SOCKET].Bufferlenght = Bufferlenght;
	UDP_sockettable[SOCKET].Recivebuffer = UDP_Recivebuffer;
	UDP_sockettable[SOCKET].ttl = UDP_Default_ttl;
		
	if ( IP == 0xffffffff ) 
	{
		for( unsigned char i = 0 ; i < 6 ; i++ ) UDP_sockettable[SOCKET].MACadress[i] = 0xff;
		return( SOCKET );
	}
	if ( IS_ADDR_IN_MY_SUBNET( IP, Netmask ) )
		if ( IS_BROADCAST_ADDR( IP, Netmask ) ) for( unsigned char i = 0 ; i < 6 ; i++ ) UDP_sockettable[SOCKET].MACadress[i] = 0xff;
		else GetIP2MAC( IP, &UDP_sockettable[SOCKET].MACadress );
	else GetIP2MAC( Gateway, &UDP_sockettable[SOCKET].MACadress );

	return(SOCKET);
}
Example #2
0
/* -----------------------------------------------------------------------------------------------------------*/
int UDP_RegisterSocket( long IP, unsigned int DestinationPort, int Bufferlenght, char * UDP_Recivebuffer)
{
//	struct IP_CONFIG ip_config;
//	ip_getconfig( &ip_config );
	
	int socket,i;
	char temp;
	
	temp = SREG;
	cli();
	
	socket = UDP_Getfreesocket();

	if ( socket != UDP_SOCKET_ERROR )
	{
		UDP_sockettable[socket].Socketstate = UDP_SOCKET_READY;
		UDP_sockettable[socket].DestinationPort = DestinationPort ;
		// wenn Zielport Bootps(67) dann Sourceport auf Bootpc(68) setzen um kommunikation mit DHCP-Server zu ermöglichen
		if ( DestinationPort == 67 )
			UDP_sockettable[socket].SourcePort = 68 ;
		else
			UDP_sockettable[socket].SourcePort =~ DestinationPort;

		UDP_sockettable[socket].DestinationIP = IP;
		UDP_sockettable[socket].Bufferfill = 0;
		UDP_sockettable[socket].Bufferlenght = Bufferlenght;
		UDP_sockettable[socket].Recivebuffer = UDP_Recivebuffer;
		UDP_sockettable[socket].UDPcallback = NULL;

		// if an broadcast ?
		if ( IP == 0xffffffff ) 
		{
			for( i = 0 ; i < 6 ; i++ )
			{
				UDP_sockettable[socket].MACadress[i] = 0xff;
			}
		}
		// need MAC-address ?
//		else if ( IS_ADDR_IN_MY_SUBNET( IP, ip_config.Netmask ) )
		else if ( IS_ADDR_IN_MY_SUBNET( IP, Netmask ) )
		{
			if ( IS_BROADCAST_ADDR( IP, Netmask ) )
			{
				for( i = 0 ; i < 6 ; i++ )
				{
					UDP_sockettable[socket].MACadress[i] = 0xff;
				}
			}
			else
			{
				SREG = temp;
				GetIP2MAC( IP, UDP_sockettable[socket].MACadress );
				temp = SREG;
				cli();
			}
		}
#if defined(MULTICAST)
		// Check if we got a multicast address.
		// Remember the IP address is already in network byte order, so we check
		// the lowest byte for the multicast IP address bits.
		else if ( (IP & 0xf0) == 0xe0 )
		{
			// Yes, we have an IP multicast, set MAC to multicast.
			// First chop the IP address into bytes.
			union IP_ADDRESS IPnum;
			IPnum.IP = IP;

			UDP_sockettable[socket].MACadress[0] = 0x01;
			UDP_sockettable[socket].MACadress[1] = 0x00;
			UDP_sockettable[socket].MACadress[2] = 0x5e;

			// Conforming to the rules the 24th bit must be set to 0.
			// The remaining 23 bits are mapped as they are.
			UDP_sockettable[socket].MACadress[3] =  IPnum.IPbyte[1] & 0x7f;
			UDP_sockettable[socket].MACadress[4] =  IPnum.IPbyte[2];
			UDP_sockettable[socket].MACadress[5] =  IPnum.IPbyte[3];
		}
#endif
		else
		{
			SREG = temp;
			GetIP2MAC( Gateway, UDP_sockettable[socket].MACadress );
			temp = SREG;
			cli();
		}
	}
	
	SREG = temp;
	return( socket );
}