Skip to content

Commit

Permalink
Merge pull request baresip#843 from alfredh/net_stuff
Browse files Browse the repository at this point in the history
Added 'net_set_address' and 'net_set_af' API functions.
  • Loading branch information
juha-h authored Nov 3, 2019
2 parents 863d31c + a5da3c5 commit 70a144d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,13 @@ typedef void (net_change_h)(void *arg);
int net_alloc(struct network **netp, const struct config_net *cfg);
int net_use_nameserver(struct network *net,
const struct sa *srvv, size_t srvc);
void net_set_address(struct network *net, const struct sa *ip);
void net_change(struct network *net, uint32_t interval,
net_change_h *ch, void *arg);
void net_force_change(struct network *net);
bool net_check(struct network *net);
int net_af(const struct network *net);
int net_set_af(struct network *net, int af);
int net_dns_debug(struct re_printf *pf, const struct network *net);
int net_debug(struct re_printf *pf, const struct network *net);
const struct sa *net_laddr_af(const struct network *net, int af);
Expand Down
44 changes: 44 additions & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,30 @@ int net_use_nameserver(struct network *net, const struct sa *srvv, size_t srvc)
}


/**
* Set network IP address
*
* @param net Network instance
* @param ip IP address
*/

void net_set_address(struct network *net, const struct sa *ip)
{
switch (sa_af(ip)) {

case AF_INET:
sa_cpy(&net->laddr, ip);
return;

#ifdef HAVE_INET6
case AF_INET6:
sa_cpy(&net->laddr6, ip);
return;
#endif
}
}


/**
* Check for networking changes with a regular interval
*
Expand Down Expand Up @@ -566,6 +590,26 @@ int net_af(const struct network *net)
}


/**
* Set the preferred address family (AF)
*
* @param net Network instance
* @param Preferred address family
*
* @return 0 if success, otherwise errorcode
*/
int net_set_af(struct network *net, int af)
{
if (af != AF_INET && af != AF_INET6)
return EAFNOSUPPORT;

if (net)
net->af = af;

return 0;
}


/**
* Print networking debug information
*
Expand Down

0 comments on commit 70a144d

Please sign in to comment.