From 13cd1199b92b98241d594c02873cd80a218a80ac Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 16 Nov 2010 20:47:37 +0100 Subject: sccp: Rewrite the sccp_test_addr to set the size correctly Fix the code to set the number of consumed bytes correctly and return the number of bytes consumed for for the address. Add a simple but expandable test case to test the SCCP address --- src/sccp.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/sccp.c') diff --git a/src/sccp.c b/src/sccp.c index 1869631..e5b0e02 100644 --- a/src/sccp.c +++ b/src/sccp.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -483,30 +484,37 @@ static int _sccp_parse_err(struct msgb *msgb, struct sccp_parse_result *result) int sccp_create_sccp_addr(struct msgb *msg, const struct sockaddr_sccp *sock) { - int pos = 2; - uint8_t *data; + uint8_t *len, *ai, *gti; + + len = msgb_put(msg, 1); + ai = msgb_put(msg, 1); - data = msgb_put(msg, 1 + 2 + sock->gti_len); - data[0] = 2; if (sock->gti) - data[1] = 0 << 6 | (sock->gti_ind & 0x0f) << 2; + ai[0] = 0 << 6 | (sock->gti_ind & 0x0f) << 2; else - data[1] = 1 << 6 | 1 << 1; + ai[0] = 1 << 6 | 1 << 1; /* store a point code */ if (sock->use_poi) { - msgb_put(msg, 2); - data[1] |= 0x01; - data[pos++] = sock->poi[0]; - data[pos++] = sock->poi[1]; - } + uint8_t *poi; + ai[0] |= 0x01; + poi = msgb_put(msg, 2); + poi[0] = sock->poi[0]; + poi[1] = sock->poi[1]; + } - data[pos++] = sock->sccp_ssn; + /* copy the SSN */ + msgb_v_put(msg, sock->sccp_ssn); /* copy the gti if it is present */ - memcpy(&data[pos++], sock->gti, sock->gti_len); + gti = msgb_put(msg, sock->gti_len); + memcpy(gti, sock->gti, sock->gti_len); + + /* update the length now */ + len[0] = msg->tail - len - 1; + return len[0] + 1; } /* -- cgit v1.2.3