This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3000 Struct sockaddr_in



Hello,

I have one question.
I want use sockaddr_in structure to create UDP client mode.

This structure looks like this:

typedef struct _sockaddr_in_t
{
short sin_family;                                                       // e.g. AF_INET
unsigned short sin_port;                                        // e.g. htons(3490)
in_addr sin_addr;                                                    // see struct in_addr, below
char sin_zero[8];                                                      // zero this if you want to
} sockaddr_in;

if i want define this parametars, i can do that this:

sockaddr_in adress;
adress.sin_family=AF_INET;
adress.sin_port=htons(port);

sin_addr structure looks like this:

typedef struct _in_addr_t
{
unsigned long s_addr;                 // load with inet_aton()
} in_addr;

 If i want set this tipe of code i must use inet_aton() to set Ip address. This function doesn't existc in Host Driver of CC3000.
is it possible to use this structure without hist inet_aton() function? 
If it is possible, can someone type the example.  

 

  • Hi,

    Yes, you can use "in_addr"  structure.

    Use the following code to convert IP address into desired format.

    unsigned long inet_aton(unsigned char *IpAdd)
    {
    unsigned long Ip = 0;

    Ip = (Ip | IpAdd[3])<<8;
    Ip = (Ip | IpAdd[2])<<8;
    Ip = (Ip | IpAdd[1])<<8;
    Ip = (Ip | IpAdd[0]);
    return Ip;
    }

    Argument to function is a pointer to array containing the IP address.

    unsigned char IpAddr[4] = {192,168,1,100};

     address.sin_addr.s_addr = inet_aton(IpAddr);

    Regards,

    Ankur