bundle.c (36368) | bundle.c (36450) |
---|---|
1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $Id: bundle.c,v 1.7 1998/05/25 02:22:30 brian Exp $ | 26 * $Id: bundle.c,v 1.8 1998/05/25 10:37:00 brian Exp $ |
27 */ 28 29#include <sys/types.h> 30#include <sys/socket.h> 31#include <netinet/in.h> 32#include <net/if.h> 33#include <arpa/inet.h> 34#include <net/route.h> --- 1304 unchanged lines hidden (view full) --- 1339bundle_ReceiveDatalink(struct bundle *bundle, int s, struct sockaddr_un *sun) 1340{ 1341 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)]; 1342 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf; 1343 struct msghdr msg; 1344 struct iovec iov[SCATTER_SEGMENTS]; 1345 struct datalink *dl; 1346 int niov, link_fd, expect, f; | 27 */ 28 29#include <sys/types.h> 30#include <sys/socket.h> 31#include <netinet/in.h> 32#include <net/if.h> 33#include <arpa/inet.h> 34#include <net/route.h> --- 1304 unchanged lines hidden (view full) --- 1339bundle_ReceiveDatalink(struct bundle *bundle, int s, struct sockaddr_un *sun) 1340{ 1341 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)]; 1342 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf; 1343 struct msghdr msg; 1344 struct iovec iov[SCATTER_SEGMENTS]; 1345 struct datalink *dl; 1346 int niov, link_fd, expect, f; |
1347 pid_t pid; |
|
1347 1348 log_Printf(LogPHASE, "Receiving datalink\n"); 1349 1350 /* Create our scatter/gather array */ 1351 niov = 1; 1352 iov[0].iov_len = strlen(Version) + 1; 1353 iov[0].iov_base = (char *)malloc(iov[0].iov_len); | 1348 1349 log_Printf(LogPHASE, "Receiving datalink\n"); 1350 1351 /* Create our scatter/gather array */ 1352 niov = 1; 1353 iov[0].iov_len = strlen(Version) + 1; 1354 iov[0].iov_base = (char *)malloc(iov[0].iov_len); |
1354 if (datalink2iov(NULL, iov, &niov, sizeof iov / sizeof *iov) == -1) { | 1355 if (datalink2iov(NULL, iov, &niov, sizeof iov / sizeof *iov, 0) == -1) { |
1355 close(s); 1356 return; 1357 } 1358 | 1356 close(s); 1357 return; 1358 } 1359 |
1360 pid = getpid(); 1361 write(s, &pid, sizeof pid); 1362 |
|
1359 for (f = expect = 0; f < niov; f++) 1360 expect += iov[f].iov_len; 1361 1362 /* Set up our message */ 1363 cmsg->cmsg_len = sizeof cmsgbuf; 1364 cmsg->cmsg_level = SOL_SOCKET; 1365 cmsg->cmsg_type = 0; 1366 --- 57 unchanged lines hidden (view full) --- 1424void 1425bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun) 1426{ 1427 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)], ack; 1428 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf; 1429 struct msghdr msg; 1430 struct iovec iov[SCATTER_SEGMENTS]; 1431 int niov, link_fd, f, expect; | 1363 for (f = expect = 0; f < niov; f++) 1364 expect += iov[f].iov_len; 1365 1366 /* Set up our message */ 1367 cmsg->cmsg_len = sizeof cmsgbuf; 1368 cmsg->cmsg_level = SOL_SOCKET; 1369 cmsg->cmsg_type = 0; 1370 --- 57 unchanged lines hidden (view full) --- 1428void 1429bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun) 1430{ 1431 char cmsgbuf[sizeof(struct cmsghdr) + sizeof(int)], ack; 1432 struct cmsghdr *cmsg = (struct cmsghdr *)cmsgbuf; 1433 struct msghdr msg; 1434 struct iovec iov[SCATTER_SEGMENTS]; 1435 int niov, link_fd, f, expect; |
1436 pid_t newpid; |
|
1432 1433 log_Printf(LogPHASE, "Transmitting datalink %s\n", dl->name); 1434 1435 bundle_LinkClosed(dl->bundle, dl); 1436 bundle_DatalinkLinkout(dl->bundle, dl); 1437 1438 /* Build our scatter/gather array */ 1439 iov[0].iov_len = strlen(Version) + 1; 1440 iov[0].iov_base = strdup(Version); 1441 niov = 1; 1442 | 1437 1438 log_Printf(LogPHASE, "Transmitting datalink %s\n", dl->name); 1439 1440 bundle_LinkClosed(dl->bundle, dl); 1441 bundle_DatalinkLinkout(dl->bundle, dl); 1442 1443 /* Build our scatter/gather array */ 1444 iov[0].iov_len = strlen(Version) + 1; 1445 iov[0].iov_base = strdup(Version); 1446 niov = 1; 1447 |
1443 link_fd = datalink2iov(dl, iov, &niov, sizeof iov / sizeof *iov); | 1448 read(s, &newpid, sizeof newpid); 1449 link_fd = datalink2iov(dl, iov, &niov, sizeof iov / sizeof *iov, newpid); |
1444 1445 if (link_fd != -1) { 1446 memset(&msg, '\0', sizeof msg); 1447 1448 msg.msg_name = (caddr_t)sun; 1449 msg.msg_namelen = sizeof *sun; 1450 msg.msg_iov = iov; 1451 msg.msg_iovlen = niov; --- 85 unchanged lines hidden (view full) --- 1537 signal(SIGALRM, SIG_DFL); 1538 for (fd = getdtablesize(); fd > 2; fd--) 1539 close(fd); 1540 execl(CATPROG, name, NULL); 1541 _exit(0); 1542 break; 1543 } 1544 } | 1450 1451 if (link_fd != -1) { 1452 memset(&msg, '\0', sizeof msg); 1453 1454 msg.msg_name = (caddr_t)sun; 1455 msg.msg_namelen = sizeof *sun; 1456 msg.msg_iov = iov; 1457 msg.msg_iovlen = niov; --- 85 unchanged lines hidden (view full) --- 1543 signal(SIGALRM, SIG_DFL); 1544 for (fd = getdtablesize(); fd > 2; fd--) 1545 close(fd); 1546 execl(CATPROG, name, NULL); 1547 _exit(0); 1548 break; 1549 } 1550 } |
1545 close(s); | |
1546 close(link_fd); 1547 } | 1551 close(link_fd); 1552 } |
1553 close(s); |
|
1548 1549 while (niov--) 1550 free(iov[niov].iov_base); 1551} 1552 1553int 1554bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, 1555 const char *name) --- 46 unchanged lines hidden --- | 1554 1555 while (niov--) 1556 free(iov[niov].iov_base); 1557} 1558 1559int 1560bundle_RenameDatalink(struct bundle *bundle, struct datalink *ndl, 1561 const char *name) --- 46 unchanged lines hidden --- |