Changeset 2058 for Whitix/trunk

Show
Ignore:
Timestamp:
05/27/09 08:08:10 (3 years ago)
Author:
mwhitworth
Message:

Add patch from Dan Fandrich: provide a implementation of endian conversion functions in user/posix/socket/socket.c.

Location:
Whitix/trunk/user/posix
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/user/posix/include/netinet/in.h

    r608 r2058  
    3434 
    3535#define INADDR_LOOPBACK         0x7F000001 
     36#define INADDR_ANY              0L 
     37#define INADDR_BROADCAST        0xFFFFFFFF 
    3638 
    3739struct ip_mreqn 
     
    4446typedef unsigned long in_addr_t; 
    4547 
     48extern unsigned short ntohs(unsigned short s); 
     49extern unsigned short htons(unsigned short s); 
     50extern unsigned long ntohl(unsigned long l); 
     51extern unsigned long htonl(unsigned long l); 
     52 
    4653#endif 
  • Whitix/trunk/user/posix/socket/socket.c

    r1825 r2058  
    9999} 
    100100 
     101/* NOTE: The following functions are for little-endian systems only */ 
    101102unsigned short ntohs(unsigned short s) 
    102103{ 
    103         printf("ntohs\n"); 
    104         return 0; 
     104        return ((s & 0x00ff) << 8) | 
     105               ((s & 0xff00) >> 8); 
     106 
    105107} 
    106108 
    107 short htons(short s) 
     109unsigned short htons(unsigned short s) 
    108110{ 
    109         printf("htons\n"); 
    110         return 0; 
     111        return ntohs(s); 
    111112} 
    112113 
    113114unsigned long ntohl(unsigned long l) 
    114115{ 
    115         printf("ntohl\n"); 
    116         return 0; 
     116        return ((l & 0x000000ffU) << 24) | 
     117               ((l & 0x0000ff00U) <<  8) | 
     118               ((l & 0x00ff0000U) >>  8) | 
     119               ((l & 0xff000000U) >> 24); 
    117120} 
    118121 
    119 long htonl(long l) 
     122unsigned long htonl(unsigned long l) 
    120123{ 
    121         printf("htonl\n"); 
    122         return 0; 
     124        return ntohl(l); 
    123125} 
    124126