Revision 48e5f32d sysdep/bsd/sysio.h

View differences:

sysdep/bsd/sysio.h
38 38
  ipa_ntoh(*a);
39 39
}
40 40

  
41
static inline char *
42
sysio_bind_to_iface(sock *s)
43
{
44
  /* Unfortunately not available */
45
  return NULL;
46
}
47

  
48 41

  
49 42
#else
50 43

  
51 44
#include <net/if.h>
52 45
#include <net/if_dl.h>
46
#include <netinet/in_systm.h> // Workaround for some BSDs
47
#include <netinet/ip.h>
53 48

  
54 49
static inline void
55 50
set_inaddr(struct in_addr * ia, ip_addr a)
......
93 88
static inline char *
94 89
sysio_join_group(sock *s, ip_addr maddr)
95 90
{
96
	struct ip_mreq  mreq;
91
	struct ip_mreq mreq;
97 92

  
98 93
	bzero(&mreq, sizeof(mreq));
99 94
	set_inaddr(&mreq.imr_interface, s->iface->addr->ip);
......
152 147
  return NULL;
153 148
}
154 149

  
155
static void
150
static inline void
156 151
sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
157 152
{
158 153
  struct cmsghdr *cm;
......
190 185
}
191 186

  
192 187
/* Unfortunately, IP_SENDSRCADDR does not work for raw IP sockets on BSD kernels */
193
/*
194
static void
188

  
189
static inline void
195 190
sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg, void *cbuf, size_t cbuflen)
196 191
{
192
#ifdef IP_SENDSRCADDR
197 193
  struct cmsghdr *cm;
198 194
  struct in_addr *sa;
199 195

  
200
  if (!(s->flags & SKF_LADDR_TX))
201
    return;
202

  
203 196
  msg->msg_control = cbuf;
204 197
  msg->msg_controllen = cbuflen;
205 198

  
206
  if (s->iface)
207
    {
208
      struct in_addr m;
209
      set_inaddr(&m, s->saddr);
210
      setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &m, sizeof(m));
211
    }
212

  
213 199
  cm = CMSG_FIRSTHDR(msg);
214 200
  cm->cmsg_level = IPPROTO_IP;
215 201
  cm->cmsg_type = IP_SENDSRCADDR;
......
219 205
  set_inaddr(sa, s->saddr);
220 206

  
221 207
  msg->msg_controllen = cm->cmsg_len;
208
#endif
209
}
210

  
211

  
212
static void
213
fill_ip_header(sock *s, void *hdr, int dlen)
214
{
215
  struct ip *ip = hdr;
216

  
217
  bzero(ip, 20);
218

  
219
  ip->ip_v = 4;
220
  ip->ip_hl = 5;
221
  ip->ip_tos = (s->tos < 0) ? 0 : s->tos;
222
  ip->ip_len = 20 + dlen;
223
  ip->ip_ttl = (s->ttl < 0) ? 64 : s->ttl;
224
  ip->ip_p = s->dport;
225
  set_inaddr(&ip->ip_src, s->saddr);
226
  set_inaddr(&ip->ip_dst, s->daddr);
227

  
228
#ifdef __OpenBSD__
229
  /* OpenBSD expects ip_len in network order, other BSDs expect host order */
230
  ip->ip_len = htons(ip->ip_len);
231
#endif
222 232
}
223
*/
224 233

  
225 234
#endif
226 235

  

Also available in: Unified diff