OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) University of Washington | 3 * Copyright (c) University of Washington |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 * | 46 * |
47 * \param path The socket address information from the Unix socket we use | 47 * \param path The socket address information from the Unix socket we use |
48 * to send the created socket back to. | 48 * to send the created socket back to. |
49 * \param fd The file descriptor we're going to send. | 49 * \param fd The file descriptor we're going to send. |
50 * \param magic_number A verification number to verify the caller is talking to
the | 50 * \param magic_number A verification number to verify the caller is talking to
the |
51 * right process. | 51 * right process. |
52 */ | 52 */ |
53 void | 53 void |
54 SendSocket (const char *path, int fd, const int magic_number) | 54 SendSocket (const char *path, int fd, const int magic_number) |
55 { | 55 { |
| 56 (void)magic_number; // make compiler happy |
56 // | 57 // |
57 // Open a Unix (local interprocess) socket to call back to the emu net | 58 // Open a Unix (local interprocess) socket to call back to the emu net |
58 // device. | 59 // device. |
59 // | 60 // |
60 LOG ("Create Unix socket"); | 61 LOG ("Create Unix socket"); |
61 int sock = socket (PF_UNIX, SOCK_DGRAM, 0); | 62 int sock = socket (PF_UNIX, SOCK_DGRAM, 0); |
62 ABORT_IF (sock == -1, "Unable to open socket", 1); | 63 ABORT_IF (sock == -1, "Unable to open socket", 1); |
63 | 64 |
64 // | 65 // |
65 // We have this string called path, which is really a hex representation | 66 // We have this string called path, which is really a hex representation |
66 // of the endpoint that the net device created. It used a forward encoding | 67 // of the endpoint that the net device created. It used a forward encoding |
67 // method (BufferToString) to take the sockaddr_un it made and passed | 68 // method (BufferToString) to take the sockaddr_un it made and passed |
68 // the resulting string to us. So we need to take the inverse method | 69 // the resulting string to us. So we need to take the inverse method |
69 // (StringToBuffer) and build the same sockaddr_un over here. | 70 // (StringToBuffer) and build the same sockaddr_un over here. |
70 // | 71 // |
71 socklen_t clientAddrLen; | 72 socklen_t clientAddrLen; |
72 struct sockaddr_un clientAddr; | 73 struct sockaddr_un clientAddr; |
73 | 74 |
74 LOG ("Decode address " << path); | 75 LOG ("Decode address " << path); |
75 bool rc = ns3::StringToBuffer (path, (uint8_t *)&clientAddr, &clientAddrLen); | 76 bool rc = ns3::StringToBuffer (path, (uint8_t *)&clientAddr, (uint32_t *)&clie
ntAddrLen); |
76 ABORT_IF (rc == false, "Unable to decode path", 0); | 77 ABORT_IF (rc == false, "Unable to decode path", 0); |
77 | 78 |
78 LOG ("Connect"); | 79 LOG ("Connect"); |
79 int status = connect (sock, (struct sockaddr*)&clientAddr, clientAddrLen); | 80 int status = connect (sock, (struct sockaddr*)&clientAddr, clientAddrLen); |
80 ABORT_IF (status == -1, "Unable to connect to emu device", 1); | 81 ABORT_IF (status == -1, "Unable to connect to emu device", 1); |
81 | 82 |
82 LOG ("Connected"); | 83 LOG ("Connected"); |
83 | 84 |
84 // | 85 // |
85 // This is arcane enough that a few words are worthwhile to explain what's | 86 // This is arcane enough that a few words are worthwhile to explain what's |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // We also have to update the controllen in case other stuff is actually | 157 // We also have to update the controllen in case other stuff is actually |
157 // in there we may not be aware of (due to macros). | 158 // in there we may not be aware of (due to macros). |
158 // | 159 // |
159 msg.msg_controllen = cmsg->cmsg_len; | 160 msg.msg_controllen = cmsg->cmsg_len; |
160 | 161 |
161 // | 162 // |
162 // Finally, we get a pointer to the start of the ancillary data array and | 163 // Finally, we get a pointer to the start of the ancillary data array and |
163 // put our file descriptor in. | 164 // put our file descriptor in. |
164 // | 165 // |
165 int *fdptr = (int*)(CMSG_DATA (cmsg)); | 166 int *fdptr = (int*)(CMSG_DATA (cmsg)); |
166 *fdptr = fd; // | 167 *fdptr = static_cast<int> (fd); // |
167 | 168 |
168 // | 169 // |
169 // Actually send the file descriptor back to the emulated net device. | 170 // Actually send the file descriptor back to the emulated net device. |
170 // | 171 // |
171 ssize_t len = sendmsg (sock, &msg, 0); | 172 ssize_t len = sendmsg (sock, &msg, 0); |
172 ABORT_IF (len == -1, "Could not send socket back to emu net device", 1); | 173 ABORT_IF (len == -1, "Could not send socket back to emu net device", 1); |
173 | 174 |
174 LOG ("sendmsg complete"); | 175 LOG ("sendmsg complete"); |
175 } | 176 } |
176 | 177 |
177 } // namespace ns3 | 178 } // namespace ns3 |
OLD | NEW |