# HG changeset patch # User Mychaela Falconia # Date 1679083637 28800 # Node ID 6ac96217c44292ad319ecda74113aa8ccfcc9a79 # Parent 62ecc0aa081f9edaee9ef1e3cc6e3a385f34d327 sip-manual-out: add SDP response parsing diff -r 62ecc0aa081f -r 6ac96217c442 sip-manual-out/Makefile --- a/sip-manual-out/Makefile Fri Mar 17 10:56:43 2023 -0800 +++ b/sip-manual-out/Makefile Fri Mar 17 12:07:17 2023 -0800 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 PROG= sip-manual-out -OBJS= bye_in.o disc_cmd.o main.o readconf.o reinvite.o rtp.o sip_log.o \ - sip_udp.o uac.o uas.o +OBJS= bye_in.o disc_cmd.o main.o readconf.o reinvite.o rtp.o sdp_in.o \ + sip_log.o sip_udp.o uac.o uas.o LIBS= ../libsip/libsip.a ../librtpalloc/librtpalloc.a ../libutil/libutil.a INSTBIN=/usr/local/bin diff -r 62ecc0aa081f -r 6ac96217c442 sip-manual-out/sdp_in.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-manual-out/sdp_in.c Fri Mar 17 12:07:17 2023 -0800 @@ -0,0 +1,74 @@ +/* + * In this module we handle SDP responses to our INVITE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "../libsip/parse.h" +#include "../libsip/sdp.h" + +extern char *get_single_header(); +extern char *extract_to_tag(); + +struct sockaddr_in rtp_remote_addr; +int pcma_selected; + +static +check_sdp_present(msg) + struct sip_pkt_rx *msg; +{ + char *hval; + + if (!msg->msg_body_len) + return 0; + hval = get_single_header(msg, "Content-Type", "c", (int *) 0); + if (!hval) + return 0; + if (!strcasecmp(hval, "application/sdp")) + return 1; + else + return 0; +} + +void +extract_resp_sdp(msg) + struct sip_pkt_rx *msg; +{ + struct sdp_parse sdp_parse; + int rc; + + if (!check_sdp_present(msg)) { + printf("INVITE response has no SDP!\n"); + return; + } + rc = parse_incoming_sdp(msg->msg_body, msg->msg_body_len, &sdp_parse); + if (rc < 0) { + printf("SDP parse error: %d\n", rc); + return; + } + switch (sdp_parse.codec_mask) { + case SDP_CODEC_MASK_PCMU: + case SDP_CODEC_MASK_BOTH: + pcma_selected = 0; + break; + case SDP_CODEC_MASK_PCMA: + case SDP_CODEC_MASK_BOTH | SDP_CODEC_MASK_PCMA_PREF: + pcma_selected = 1; + break; + default: + printf("SDP error: no supported codec\n"); + return; + } + printf("SDP response: IP %s port %u codec %s\n", + inet_ntoa(sdp_parse.ip_addr), sdp_parse.audio_port, + pcma_selected ? "PCMA" : "PCMU"); + rtp_remote_addr.sin_family = AF_INET; + rtp_remote_addr.sin_addr = sdp_parse.ip_addr; + rtp_remote_addr.sin_port = htons(sdp_parse.audio_port); +} diff -r 62ecc0aa081f -r 6ac96217c442 sip-manual-out/uac.c --- a/sip-manual-out/uac.c Fri Mar 17 10:56:43 2023 -0800 +++ b/sip-manual-out/uac.c Fri Mar 17 12:07:17 2023 -0800 @@ -106,6 +106,8 @@ if (msg->status_code >= 200) { printf("Sending ACK\n"); send_ack(sin); + if (msg->status_code <= 299) + extract_resp_sdp(msg); } }