-
Notifications
You must be signed in to change notification settings - Fork 1
/
zzechoscu.c
93 lines (88 loc) · 2.25 KB
/
zzechoscu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <assert.h>
#include <string.h>
#include "zznetwork.h"
#include "zznet.h"
enum
{
OPT_AET,
OPT_CAE,
OPT_COUNT
};
static struct zzopts opts[] =
{ { "--aet <AET>", "Our AE title", false, false, 1, 0 }, // OPT_AET
{ "--cae <AET>", "Destination AE title", false, false, 1, 0 }, // OPT_CAE
{ NULL, NULL, false, false, 0, 0 } }; // OPT_COUNT
#define UID_VerificationSOPClass "1.2.840.10008.1.1"
int main(int argc, char **argv)
{
struct zznetwork *zn = NULL;
uint16_t group, element, mesID = 1;
long len;
const char *aet = "ECHOSCU";
const char *cae = "ANY-SCP";
int argstart = zzutil(argc, argv, 2, "<host> <port>", "DICOM network test client", opts);
zn = zznetconnect("", argv[argstart], atoi(argv[argstart + 1]), 0);
if (!zn)
{
fprintf(stderr, "Failed to connect\n");
return -1;
}
if (opts[OPT_AET].found)
{
aet = argv[opts[OPT_AET].argstart + 1];
}
if (opts[OPT_CAE].found)
{
cae = argv[opts[OPT_CAE].argstart + 1];
}
strcpy(zn->out->net.aet, aet);
zznetregister(zn);
PDU_AssociateRQ(zn->out, cae, UID_VerificationSOPClass);
zigetc(zn->in->zi); // trigger read of first packet
do
{
printf("PDU Type %ld received (%ld)\n", zn->in->net.pdutype, zn->out->net.pdutype);
zisetreadpos(zn->in->zi, zireadpos(zn->in->zi) - 1); // reset read marker
switch (zn->in->net.pdutype)
{
case 0x01:
printf("ASSOCIATE-RQ received\n");
PDU_Associate_Request(zn);
break;
case 0x02:
printf("ASSOCIATE-AC received\n");
PDU_Associate_Accept(zn->in);
break;
case 0x04:
zziterinit(zn->in);
while (zziternext(zn->in, &group, &element, &len))
{
switch (ZZ_KEY(group, element))
{
case DCM_CommandGroupLength: break;
case DCM_AffectedSOPClassUID: break;
case DCM_MessageID: mesID = zzgetuint16(zn->in, 0); break;
default: break;
}
}
// Now send back an echo response
znwechoresp(zn->out, mesID);
break;
case 0x05:
PDU_Release_Handle(zn);
zznetclose(zn);
return 0;
case 0x07:
PDU_Abort_Parse(zn);
zznetclose(zn);
return 0;
default:
printf("Unknown PDU type: %x\n", (unsigned)zn->in->net.pdutype);
assert(false);
break;
}
zigetc(zn->in->zi); // Force read of PDU type for next packet
} while (zn->in->net.pdutype != UNLIMITED);
zznetclose(zn);
return 0;
}