服务器上的TCP转储与客户端不匹配

时间:2017-10-29 22:03:43

标签: go tcp sip tcpdump

我正在尝试编写一个启动MRCP会话的客户端,但它没有按预期运行。在我的调试中,我确定SIP服务器没有收到我的ACK消息来初始化会话。

这是来自客户端的tcpdump:

tcpdump src port 5060 or dst port 5060 or src port 32418 or dst port 32418 -s0 -A

17:34:35.383867 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [S], seq 3371911038, win 65535, options [mss 1366,nop,wscale 5,nop,nop,TS val 560025151 ecr 0,sackOK,eol], length 0
E..@..@.@...
...
.........G~.........|.....V.......
!aN?........
17:34:35.412489 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [S.], seq 1495905271, ack 3371911039, win 14600, options [mss 1310,nop,nop,sackOK], length 0
E..0..@...`.
...
.......Y)....G.p.9..=..........
17:34:35.412568 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [.], ack 1, win 65535, length 0
E..(]v@.@..h
...
.........G.Y)..P....s..
17:34:35.412756 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [P.], seq 1:780, ack 1, win 65535, length 779
E..3..@.@._.
...
.........G.Y)..P....c..INVITE sip:10.0.0.1:5060 SIP/2.0
Via: SIP/2.0/TCP 10.0.0.2:5090;branch=z9hG4bKuuDCoBFClGrwk
Max-Forwards: 70
From: <sip:10.0.0.2:61347>;tag=KZMlWvlA
To: <sip:10.0.0.1:5060>
Call-ID: rc-VxVmMJd-YpyrUXC-hpkkEvs-AsNeKAt
CSeq: 1509312876 INVITE
User-Agent: VoiceTest
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE
Supported: timer, 100rel
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 278

v=0
o=VoiceTest 15093128754187 15093128756831 IN IP4 10.0.0.2
s=-
c=IN IP4 10.0.0.2
t=0 0
m=application 9 TCP/MRCPv2 1
a=setup:active
a=connection:new
a=resource:speechrecog
a=cmid:1
m=audio 4062 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=sendonly
a=mid:1

17:34:35.424454 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [.], ack 780, win 13821, length 0
E..(w.@....O
...
.......Y)....J.P.5.Ik..
17:34:35.430966 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [P.], seq 1:895, ack 780, win 15580, length 894
E.....@...U.
...
.......Y)....J.P.<.`t..SIP/2.0 200 OK
Via: SIP/2.0/TCP 10.0.0.2:5090;branch=z9hG4bKuuDCoBFClGrwk;rport=57614
From: <sip:10.0.0.2:61347>;tag=KZMlWvlA
To: <sip:10.0.0.1:5060>;tag=HtjeQ38HveyBp
Call-ID: rc-VxVmMJd-YpyrUXC-hpkkEvs-AsNeKAt
CSeq: 1509312876 INVITE
Contact: <sip:10.0.0.1:5060>
User-Agent: OpenMRCP Sofia-SIP
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE
Supported: timer, 100rel
Min-SE: 120
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 328

v=0
o=MRCPServer 0 1 IN IP4 10.0.0.1
s=-
c=IN IP4 10.0.0.1
t=0 0
m=application 32418 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:F5812716BCF011E7@speechrecog
a=cmid:1
m=audio 8002 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=recvonly
a=mid:1

17:34:35.431029 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [.], ack 895, win 65535, length 0
E..(E.@.@..0
...
.........J.Y).vP...{...
17:34:35.431395 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [P.], seq 780:1074, ack 895, win 65535, length 294
E..NLo@.@..I
...
.........J.Y).vP.......ACK sip:10.0.0.1:5060 SIP/2.0
Via: SIP/2.0/TCP 10.0.0.2:5090;branch=z9hG4bKUjyOYgTYGDvpN
Max-Forwards: 70
From: <sip:10.0.0.2:61347>;tag=KZMlWvlA
To: <sip:10.0.0.1:5060>;tag=HtjeQ38HveyBp
Call-ID: rc-VxVmMJd-YpyrUXC-hpkkEvs-AsNeKAt
CSeq: 1509312876 ACK
Content-Length: 0

这是来自服务器的tcpdump:

tcpdump src port 32418 or dst port 32418 or src port 5060 or dst port 5060 -s0 -A

21:34:35.500674 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [S], seq 839953377, win 65535, options [mss 1310,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,nop,sackOK,eol], length 0
E..@..@.....
...
.......2...........N...........................
21:34:35.500739 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [S.], seq 1323670423, ack 839953378, win 14600, options [mss 1460,nop,nop,sackOK], length 0
E..0..@.@...
...
.......N...2...p.9.q...........
21:34:35.512301 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [.], ack 1, win 65535, length 0
E..((J@...9.
...
.......2...N...P.............
21:34:35.512898 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [P.], seq 1:780, ack 1, win 65535, length 779
E..3=.@... .
...
.......2...N...P.......INVITE sip:10.0.0.1:5060 SIP/2.0
Via: SIP/2.0/TCP 10.0.0.2:5090;branch=z9hG4bKuuDCoBFClGrwk
Max-Forwards: 70
From: <sip:10.0.0.2:61347>;tag=KZMlWvlA
To: <sip:10.0.0.1:5060>
Call-ID: rc-VxVmMJd-YpyrUXC-hpkkEvs-AsNeKAt
CSeq: 1509312876 INVITE
User-Agent: VoiceTest
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE
Supported: timer, 100rel
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 278

v=0
o=VoiceTest 15093128754187 15093128756831 IN IP4 10.0.0.2
s=-
c=IN IP4 10.0.0.2
t=0 0
m=application 9 TCP/MRCPv2 1
a=setup:active
a=connection:new
a=resource:speechrecog
a=cmid:1
m=audio 4062 RTP/AVP 0
a=rtpmap:0 PCMU/8000
a=sendonly
a=mid:1

21:34:35.512922 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [.], ack 780, win 15580, length 0
E..(.W@.@.|.
...
.......N...2...P.<.....
21:34:35.518359 IP 10.0.0.1.sip > 10.0.0.2.57614: Flags [P.], seq 1:895, ack 780, win 15580, length 894
E....X@.@.y.
...
.......N...2...P.<.....SIP/2.0 200 OK
Via: SIP/2.0/TCP 10.0.0.2:5090;branch=z9hG4bKuuDCoBFClGrwk;rport=57614
From: <sip:10.0.0.2:61347>;tag=KZMlWvlA
To: <sip:10.0.0.1:5060>;tag=HtjeQ38HveyBp
Call-ID: rc-VxVmMJd-YpyrUXC-hpkkEvs-AsNeKAt
CSeq: 1509312876 INVITE
Contact: <sip:10.0.0.1:5060>
User-Agent: OpenMRCP Sofia-SIP
Accept: application/sdp
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE
Supported: timer, 100rel
Min-SE: 120
Content-Type: application/sdp
Content-Disposition: session
Content-Length: 328

v=0
o=MRCPServer 0 1 IN IP4 10.0.0.1
s=-
c=IN IP4 10.0.0.1
t=0 0
m=application 32418 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:F5812716BCF011E7@speechrecog
a=cmid:1
m=audio 8002 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=recvonly
a=mid:1

21:34:35.519073 IP 10.0.0.2.57614 > 10.0.0.1.sip: Flags [.], ack 895, win 64641, length 0
E..(eT@.....
...
.......2...N...P.............

INVITE和ACK消息都通过相同的Go函数

func (c *SIPConnection) Send(msg string) error {

    fmt.Println("-- Sending SIP Request --")
    fmt.Println(msg)
    n, err := fmt.Fprintf(c.cx, msg)

    if err != nil {
        fmt.Println("Failed to send message: ", err)
        return err
    }

    if n < len(msg) {
        return fmt.Errorf("Length of data sent was less than length of message. Sent: %d, Expected %d", n, len(msg))
    }

    fmt.Println("Wrote", n, "bytes")

    return nil
}

并且它们都显示在应用程序日志中,并且它们都没有出错。谁能帮忙解释一下这里发生了什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

根据RFC 3261向您的初始contact添加INVITE标头,contact标头对于SIP INVITE请求是必需的:

  Header field          where   proxy ACK BYE CAN INV OPT REG
  ___________________________________________________________
  Accept                  R            -   o   -   o   m*  o
  Accept                 2xx           -   -   -   o   m*  o
  Accept                 415           -   c   -   c   c   c
  Accept-Encoding         R            -   o   -   o   o   o
  Accept-Encoding        2xx           -   -   -   o   m*  o
  Accept-Encoding        415           -   c   -   c   c   c
  Accept-Language         R            -   o   -   o   o   o
  Accept-Language        2xx           -   -   -   o   m*  o
  Accept-Language        415           -   c   -   c   c   c
  Alert-Info              R      ar    -   -   -   o   -   -
  Alert-Info             180     ar    -   -   -   o   -   -
  Allow                   R            -   o   -   o   o   o
  Allow                  2xx           -   o   -   m*  m*  o
  Allow                   r            -   o   -   o   o   o
  Allow                  405           -   m   -   m   m   m
  Authentication-Info    2xx           -   o   -   o   o   o
  Authorization           R            o   o   o   o   o   o
  Call-ID                 c       r    m   m   m   m   m   m
  Call-Info                      ar    -   -   -   o   o   o
  Contact                 R            o   -   -   m   o   o