udp.c (f4359ccbbcba2c5a0fbb89a2465e8abaf93a9600) udp.c (057f1760a8171825b260dad27502f74ed5f69faf)
1/*-
2 * Copyright (c) 1999 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

--- 59 unchanged lines hidden (view full) ---

68struct udpdevice {
69 struct device dev; /* What struct physical knows about */
70 struct sockaddr_in sock; /* peer address */
71 unsigned connected : 2; /* Have we connect()d ? */
72};
73
74#define device2udp(d) ((d)->type == UDP_DEVICE ? (struct udpdevice *)d : NULL)
75
1/*-
2 * Copyright (c) 1999 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

--- 59 unchanged lines hidden (view full) ---

68struct udpdevice {
69 struct device dev; /* What struct physical knows about */
70 struct sockaddr_in sock; /* peer address */
71 unsigned connected : 2; /* Have we connect()d ? */
72};
73
74#define device2udp(d) ((d)->type == UDP_DEVICE ? (struct udpdevice *)d : NULL)
75
76int
76unsigned
77udp_DeviceSize(void)
78{
79 return sizeof(struct udpdevice);
80}
81
82static ssize_t
83udp_Sendto(struct physical *p, const void *v, size_t n)
84{

--- 48 unchanged lines hidden (view full) ---

133{
134 struct udpdevice *dev = device2udp(p->handler);
135
136 free(dev);
137}
138
139static void
140udp_device2iov(struct device *d, struct iovec *iov, int *niov,
77udp_DeviceSize(void)
78{
79 return sizeof(struct udpdevice);
80}
81
82static ssize_t
83udp_Sendto(struct physical *p, const void *v, size_t n)
84{

--- 48 unchanged lines hidden (view full) ---

133{
134 struct udpdevice *dev = device2udp(p->handler);
135
136 free(dev);
137}
138
139static void
140udp_device2iov(struct device *d, struct iovec *iov, int *niov,
141 int maxiov, int *auxfd, int *nauxfd)
141 int maxiov __unused, int *auxfd __unused, int *nauxfd __unused)
142{
143 int sz = physical_MaxDeviceSize();
144
145 iov[*niov].iov_base = realloc(d, sz);
146 if (iov[*niov].iov_base == NULL) {
147 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
148 AbortProgram(EX_OSERR);
149 }

--- 19 unchanged lines hidden (view full) ---

169 udp_device2iov,
170 NULL,
171 NULL,
172 NULL
173};
174
175struct device *
176udp_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
142{
143 int sz = physical_MaxDeviceSize();
144
145 iov[*niov].iov_base = realloc(d, sz);
146 if (iov[*niov].iov_base == NULL) {
147 log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz);
148 AbortProgram(EX_OSERR);
149 }

--- 19 unchanged lines hidden (view full) ---

169 udp_device2iov,
170 NULL,
171 NULL,
172 NULL
173};
174
175struct device *
176udp_iov2device(int type, struct physical *p, struct iovec *iov, int *niov,
177 int maxiov, int *auxfd, int *nauxfd)
177 int maxiov __unused, int *auxfd __unused, int *nauxfd __unused)
178{
179 if (type == UDP_DEVICE) {
180 struct udpdevice *dev = (struct udpdevice *)iov[(*niov)++].iov_base;
181
182 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
183 if (dev == NULL) {
184 log_Printf(LogALERT, "Failed to allocate memory: %d\n",
185 (int)(sizeof *dev));

--- 150 unchanged lines hidden ---
178{
179 if (type == UDP_DEVICE) {
180 struct udpdevice *dev = (struct udpdevice *)iov[(*niov)++].iov_base;
181
182 dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */
183 if (dev == NULL) {
184 log_Printf(LogALERT, "Failed to allocate memory: %d\n",
185 (int)(sizeof *dev));

--- 150 unchanged lines hidden ---