OLD | NEW |
1 #include "cmsg.h" | 1 #include "cmsg.h" |
2 #include <sys/socket.h> | 2 #include <sys/socket.h> |
3 #include <string.h> | 3 #include <string.h> |
4 | 4 |
5 namespace ns3 { | 5 namespace ns3 { |
6 | 6 |
7 Cmsg::Cmsg (struct msghdr *msg) | 7 Cmsg::Cmsg (struct msghdr *msg) |
8 : m_msg (msg), | 8 : m_msg (msg), |
9 m_current ((uint8_t *)msg->msg_control), | 9 m_current ((uint8_t *)msg->msg_control), |
10 m_len (msg->msg_controllen) | 10 m_len (msg->msg_controllen) |
(...skipping 10 matching lines...) Expand all Loading... |
21 struct cmsghdr msghdr; | 21 struct cmsghdr msghdr; |
22 msghdr.cmsg_len = cmsglen; | 22 msghdr.cmsg_len = cmsglen; |
23 msghdr.cmsg_level = level; | 23 msghdr.cmsg_level = level; |
24 msghdr.cmsg_type = type; | 24 msghdr.cmsg_type = type; |
25 memcpy (m_current, &msghdr, sizeof (struct cmsghdr));·· | 25 memcpy (m_current, &msghdr, sizeof (struct cmsghdr));·· |
26 memcpy (CMSG_DATA ((struct cmsghdr*)m_current), buffer, cmsglen-sizeof (struct
cmsghdr)); | 26 memcpy (CMSG_DATA ((struct cmsghdr*)m_current), buffer, cmsglen-sizeof (struct
cmsghdr)); |
27 m_current += cmsglen; | 27 m_current += cmsglen; |
28 m_len -= cmsglen; | 28 m_len -= cmsglen; |
29 } | 29 } |
30 | 30 |
| 31 |
| 32 int |
| 33 Cmsg::GetNext(int *level, int *type, int *len, uint8_t **buffer) |
| 34 { |
| 35 struct cmsghdr *cm = NULL; |
| 36 |
| 37 if (m_len < (int)CMSG_LEN(0)) |
| 38 return -1; |
| 39 |
| 40 cm = (struct cmsghdr *)m_current; |
| 41 if (cm->cmsg_len == 0 || (int)cm->cmsg_len > m_len) |
| 42 return -(1); |
| 43 |
| 44 *level = cm->cmsg_level; |
| 45 *type = cm->cmsg_type; |
| 46 *len = cm->cmsg_len - CMSG_LEN(0); |
| 47 *buffer = CMSG_DATA(cm); |
| 48 |
| 49 m_current += CMSG_ALIGN(cm->cmsg_len); |
| 50 m_len -= CMSG_ALIGN(cm->cmsg_len); |
| 51 |
| 52 return 0; |
| 53 } |
| 54 |
31 void· | 55 void· |
32 Cmsg::Finish (void) | 56 Cmsg::Finish (void) |
33 { | 57 { |
34 m_msg->msg_controllen -= m_len; | 58 m_msg->msg_controllen -= m_len; |
35 } | 59 } |
36 | 60 |
37 | 61 |
38 } // namespace ns3 | 62 } // namespace ns3 |
OLD | NEW |