socket_bind.c 379 B

123456789101112131415
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <errno.h>
  5. #include "socket.h"
  6. #include "byte.h"
  7. int socket_bind(int fd,const unsigned char *ip,const unsigned char *port)
  8. {
  9. struct sockaddr_in sa;
  10. byte_zero(&sa,sizeof sa);
  11. byte_copy(&sa.sin_addr,4,ip);
  12. byte_copy(&sa.sin_port,2,port);
  13. return bind(fd,(struct sockaddr *) &sa,sizeof sa);
  14. }