memcpy

lat

Jul 11th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. int parser::packet_len (int fd)
  2. {
  3.     ssize_t a;
  4.     unsigned char pkt_type;
  5.     static const int lengths[] = {131, 1, 1, 1028, 7, 9, 8, 74, 10, 7, 5, 4, 2, 66, 65, 2, 0};
  6.    
  7.     a = recv(fd, &pkt_type, 1, MSG_PEEK);
  8.     if (a < 1)
  9.         return -1;
  10.    
  11.     if (pkt_type > 0x0F)
  12.         return -1;
  13.    
  14.     return lengths[pkt_type];
  15. }
Advertisement
Add Comment
Please, Sign In to add comment