Lines Matching defs:req
49 struct isns_req *req;
51 req = calloc(1, sizeof(struct isns_req));
52 if (req == NULL) {
56 req->ir_buflen = sizeof(struct isns_hdr);
57 req->ir_usedlen = 0;
58 req->ir_buf = calloc(1, req->ir_buflen);
59 if (req->ir_buf == NULL) {
60 free(req);
64 return (req);
70 struct isns_req *req;
73 req = isns_req_alloc();
74 req->ir_usedlen = sizeof(struct isns_hdr);
75 hdr = (struct isns_hdr *)req->ir_buf;
79 return (req);
83 isns_req_free(struct isns_req *req)
86 free(req->ir_buf);
87 free(req);
91 isns_req_getspace(struct isns_req *req, uint32_t len)
96 if (req->ir_usedlen + len <= req->ir_buflen)
98 newlen = 1 << flsl(req->ir_usedlen + len);
99 newbuf = realloc(req->ir_buf, newlen);
104 req->ir_buf = newbuf;
105 req->ir_buflen = newlen;
110 isns_req_add(struct isns_req *req, uint32_t tag, uint32_t len,
117 isns_req_getspace(req, sizeof(*tlv) + vlen);
118 tlv = (struct isns_tlv *)&req->ir_buf[req->ir_usedlen];
124 req->ir_usedlen += sizeof(*tlv) + vlen;
128 isns_req_add_delim(struct isns_req *req)
131 isns_req_add(req, 0, 0, NULL);
135 isns_req_add_str(struct isns_req *req, uint32_t tag, const char *value)
138 isns_req_add(req, tag, strlen(value) + 1, value);
142 isns_req_add_32(struct isns_req *req, uint32_t tag, uint32_t value)
147 isns_req_add(req, tag, sizeof(value), &beval);
151 isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai)
164 isns_req_add(req, tag, sizeof(buf), buf);
168 isns_req_add(req, tag, sizeof(in6->sin6_addr), &in6->sin6_addr);
177 isns_req_add_port(struct isns_req *req, uint32_t tag, struct addrinfo *ai)
187 isns_req_add(req, tag, sizeof(buf), &buf);
192 isns_req_add(req, tag, sizeof(buf), &buf);
201 isns_req_send(int s, struct isns_req *req)
206 hdr = (struct isns_hdr *)req->ir_buf;
207 be16enc(hdr->ih_length, req->ir_usedlen - sizeof(*hdr));
213 res = write(s, req->ir_buf, req->ir_usedlen);
218 isns_req_receive(int s, struct isns_req *req)
223 req->ir_usedlen = 0;
224 isns_req_getspace(req, sizeof(*hdr));
225 res = read(s, req->ir_buf, sizeof(*hdr));
228 req->ir_usedlen = sizeof(*hdr);
229 hdr = (struct isns_hdr *)req->ir_buf;
236 isns_req_getspace(req, len);
237 res = read(s, &req->ir_buf[req->ir_usedlen], len);
240 req->ir_usedlen += len;
245 isns_req_get_status(struct isns_req *req)
248 if (req->ir_usedlen < sizeof(struct isns_hdr) + 4)
250 return (be32dec(&req->ir_buf[sizeof(struct isns_hdr)]));