router.c
// Return the file descriptor of the socket of the given UDP port
Return the file descriptor of the socket of the given UDP port
Return the file descriptor of the socket of the given UDP port
int udp_listen(int port){
  int listenfd;
  struct sockaddr_in serveraddr = {0};
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons((unsigned short)port);
  if ((listenfd = socket(AF_INET, SOCK_DGRAM, 0))  < 0)
    return SOCKET_ERROR;
  if (bind(listenfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr))<0)
    return BIND_ERROR;
  return listenfd;
}
int udp_listen ( int port ) { int listenfd ; struct sockaddr_in serveraddr = { 0 } ; serveraddr . sin_family = AF_INET ; serveraddr . sin_addr . s_addr = htonl ( INADDR_ANY ) ; serveraddr . sin_port = htons ( ( unsigned short ) port ) ; if ( ( listenfd = socket ( AF_INET , SOCK_DGRAM , 0 ) ) < 0 ) return SOCKET_ERROR ; if ( bind ( listenfd , ( struct sockaddr * ) & serveraddr , sizeof ( serveraddr ) ) < 0 ) return BIND_ERROR ; return listenfd ; }
Return the file descriptor of the socket of the given UDP port
Return the file descriptor of the socket of the given UDP port
// Open a socket in the OS // Bind to port